package com.grass.cropTradingCenter.controller.user;

import com.grass.cropTradingCenter.common.Result;
import com.grass.cropTradingCenter.pojo.dto.CropDto;
import com.grass.cropTradingCenter.pojo.dto.StartCropDto;
import com.grass.cropTradingCenter.pojo.po.StarType;
import com.grass.cropTradingCenter.pojo.vo.user.CropSearchVo;
import com.grass.cropTradingCenter.service.CropService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/crop")
@Api(tags = "用户 -- 农产品接口")
public class CropController {


    @Autowired
    CropService cropService;


    @PostMapping("/goodsList")
    @ApiOperation("农产品列表")
    public Result<List<CropDto>> goodsList(@RequestBody CropSearchVo vo) {
        return Result.success(cropService.goodsList(vo));
    }

    @GetMapping("/cropDetail/{id}")
    @ApiOperation("农产品详情")
    public Result<CropDto> cropDetail(@PathVariable("id") Integer id) {
        return Result.success(cropService.cropDetail(id));
    }

    @PostMapping("/starCrop")
    @ApiOperation("收藏或取消收藏农产品")
    public Result starCrop(@RequestBody StarType vo) {
        cropService.starCrop(vo);
        return Result.success();
    }

    @GetMapping("/starList")
    @ApiOperation("获取收藏农产品列表")
    public Result<List<StartCropDto>> getStartList(){
        return Result.success(cropService.getStartList());
    }
}
